


package model.db.table;

import java.util.ArrayList;
import model.db.Execute;


/**
 *
 * @author jc218934
 */
public class Item extends Table
{
    private static int i =1;
    private final String imgUrl;
    private final String title;
    private final String itemUrl;
    private final Integer item_id;

    public ArrayList<Bid> getBidHistory()
    {
        return bidHistory;
    }

    public String getImgUrl()
    {
        return imgUrl;
    }

    public String getItemUrl()
    {
        return itemUrl;
    }

    public Double getPrice()
    {
        return price;
    }

    public String getSellerName()
    {
        return sellerName;
    }

    public String getTitle()
    {
        return title;
    }
    private final String sellerName;
    private final Double price;
    private final ArrayList<Bid> bidHistory;

    //CREATE TABLE "biddingHistory" ("url" TEXT, "title" TEXT, "itemUrl" TEXT,
    //"sellerUrl" TEXT, "price" INTEGER, "bidHistoryId" INTEGER PRIMARY KEY  NOT NULL)

    public Item(Integer item_id, String imgUrl, String title, String itemUrl, String sellerName,
            Double price, ArrayList<Bid> bidHistory)
    {
        this.item_id = item_id;
        this.imgUrl = imgUrl;
        this.title = title;
        this.itemUrl = itemUrl;
        this.sellerName = sellerName;
        this.price = price;
        this.bidHistory = bidHistory;

    }

    @Override
    public String toString()
    {
        String str = "BidHistory: \n"
                + "imageUrl = "+imgUrl+"\n"
                + "title = "+title+"\n"
                + "description url = "+itemUrl+"\n"
                + "seller = "+sellerName+"\n"
                + "Current highest bid = "+price+"\n";
        if (bidHistory.size() >0)
        {
            str += "Bid history\n";
            for (Bid bid:bidHistory)
            {
                str += bid.toString();
            }
        }
        return str;
    }

    @Override
    public String[] getTableNames() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String[] getPrimaryKeyNames()
    {
        return new String[]{"bidHistoryId"};

    }

    @Override
    public Object[] getPrimaryKeyValues() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Class[] getPrimaryKeyTypes() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String[] getColumnNames()
    {
        return new String[]

            {"item_id", "imgUrl", "title", "itemUrl", "seller" , "price"};
    }

    @Override
    public Object[] getColumnValues()
    {
        return new Object[]
            {item_id, imgUrl, title, itemUrl, sellerName, price};
    }

    @Override
    public Class[] getColumnTypes()
    {
        return new Class[]
                {Integer.class, String.class, String.class,
                String.class, String.class, Double.class};
    }

    @Override
    public void initValues(Object[] values)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public static void createTable()
    {
        System.out.println("creating BidHistory table");
        String stringToExecute = "CREATE TABLE BID_HISTORY ("
                + "BID_HIST_ID INTEGER NOT NULL PRIMARY KEY, IMAGE_URL STRING, TITLE STRING"
                + ", DESCRIPTION_URL STRING"
                + ", SELLER_NAME STRING"
                + ", SELLER_URL STRING"
                + ", HIGHEST_BID DOUBLE)";
        Execute.execute(stringToExecute);
    }
}
